GBML manual / Maths

noise

A number from 0 to 1 that changes smoothly, not in jumps like roll_real: feed it a number that grows slowly, such as game_frame() * 0.02, and you get a wobble that never repeats in a way you can see. Use it for wind, a wandering enemy, a floating thing or a flickering flame. Give it a second number and it makes a flat sheet of noise, such as a lumpy landscape.

Syntax

noise(a, b = 0) -> real

Arguments

NameType
areal
breal (can be left out; then it is 0)

Returns

real

Description

A number from 0 to 1 that changes smoothly. roll_real jumps to a new number every time you ask; noise slides from one number to the next, so it makes a wobble that never quite repeats. Use it for wind, a wandering enemy, a floating pickup or a flickering flame.

You give it a position along the noise. Feed it a number that grows slowly, such as game_frame() * 0.02, and the answer drifts. Give it a second number and it makes a flat sheet of noise, such as a lumpy landscape.

Example

var wobble = noise(game_frame() * 0.02);
y = 80 + wobble * 20;

wobble drifts between 0 and 1, and the walker floats up and down between 80 and 100 without a pattern you can see.

How busy it is

Every whole number has a number of its own, and the numbers in between are blended with a soft curve. So noise(3.1) is close to noise(3.2), but noise(3) and noise(4) have nothing to do with each other. Bigger steps make it busier: noise(game_frame() * 0.02) drifts slowly, noise(game_frame() * 0.2) buzzes.

The small print

Cost

A few whole-number sums. No table and no memory, so it is cheap to call every frame.

On the GBA

Every whole number has a number of its own and the numbers in between are blended with a soft curve, so noise(3.1) is close to noise(3.2) but noise(3) and noise(4) are unrelated. Bigger steps make it busier: noise(game_frame() * 0.02) drifts slowly, noise(game_frame() * 0.2) buzzes. The same numbers ALWAYS give the same answer, and it does not use the roll_ numbers, so using it never changes what roll_int says. It does not need a table or any memory, only a few whole-number sums, so it is cheap to call every frame. It never goes below 0 or above 1. a and b are positions along the noise, not places in the room.

See also: roll_realwavelerpgame_frame